package org.example._01_game;

import java.io.*;

/**
 * 文件拷贝
 */
public class _03_FileCopy {
    public static void main(String[] args) {
        String sourceFile = "/Users/eddy/Desktop/test.txt";
        String targetFile = "/Users/eddy/Desktop/input.txt";
        fileCopy(sourceFile,targetFile);
    }

    private static void fileCopy(String sourceFile,String targetFile) {
//        String sourceFile = "path/to/source/file.txt";
//        String targetFile = "path/to/destination/file.txt";

        try {
            File inputFile = new File(sourceFile);
            File outputFile = new File(targetFile);

            /**
             * 字节流 bate 字节
             */
            FileInputStream inputStream = new FileInputStream(inputFile);
            FileOutputStream outputStream = new FileOutputStream(outputFile);
            
            byte[] buffer = new byte[1024];
            int length;
            
            while ((length = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, length);
            }
            
            inputStream.close();
            outputStream.close();
            
            System.out.println("File copied successfully!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
